package com.suning.boot.controller;

import com.suning.boot.entity.User;
import com.suning.boot.repository.UserRepository;
import com.suning.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserRepository userRepository;

    @Autowired
    UserService userService;

    @GetMapping("/users")
    public List<User> userList(){
        return userRepository.findAll();
    }

    @GetMapping("/useradd")
    public User userAdd(@RequestParam("username") String username,
                          @RequestParam("address") String address){
        User user = new User();
        user.setName(username);
        user.setAddress(address);
        return userRepository.save(user);
    }

    @GetMapping("/usersadd")
    public void add(){

    }

    @GetMapping("/getuser/{id}")
    public List<User> query(@PathVariable("id") Long id){
        return userRepository.findUserById(id);
    }


}
